package com.mes.md.controller;

import com.mes.common.pojo.MESResult;
import com.mes.md.service.UnitService;
import com.mes.pojo.md.Unit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author hitsune
 * @Company kafu chino
 * @Description
 * @Time 2024/10/18 18:33
 */

@RestController
@RequestMapping("/unit")
@CrossOrigin
public class UnitController {
    @Autowired
    private UnitService unitService;

    @GetMapping("/getlist")
    public MESResult unitList(Long unitId) {
        List<Unit> unitList = unitService.unitList(unitId);
        return MESResult.success(unitList);
    }

    @GetMapping("/query")
    public MESResult queryUnit(Unit unit) {
        List<Unit> unitList = unitService.queryUnitList(unit);
        return MESResult.success(unitList);
    }

    @GetMapping("/queryMainUnit")
    public MESResult queryMainUnit(){
        List<Unit> units = unitService.queryMainUnitList();
        return MESResult.success(units);
    }

    @PostMapping("/addUnit")
    public MESResult addUnit(@RequestBody Unit unit){
        Integer addUnit = unitService.addUnit(unit);
        return MESResult.success(addUnit);
    }

    @DeleteMapping("/deleteByUnitId")
    public MESResult deleteByUnitId(Long unitId){
        Integer deleteByUnitId = unitService.deleteUnit(unitId);
        return MESResult.success(deleteByUnitId);
    }

    @GetMapping("/selectById")
    public MESResult selectById(Long unitId){
        Unit unit = unitService.selectUnitById(unitId);
        return MESResult.success(unit);
    }

    @PostMapping("/editUnit")
    public MESResult editUnit(@RequestBody Unit unit){
        Integer editUnit = unitService.updateUnit(unit);
        return MESResult.success(editUnit);
    }

    @PostMapping("/deleteUnits")
    public MESResult deleteUnits(@RequestBody List<Unit> units){
        Integer deleteUnits = unitService.deleteUnits(units);
        return MESResult.success(deleteUnits);
    }
}
